package com.srxz.personnelsystem.system.repository;

import com.srxz.personnelsystem.system.entity.Position;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PositionRepository extends JpaRepository<Position, String>,JpaSpecificationExecutor<Position> {
    public Page<Position> findAll(Specification specification, Pageable pageable);

    @Query("from Position p where p.id in (select dp.positionId from DepartToPosition dp where dp.departmentId = ?1) and p.deleteTime is null and (p.status=true or p.status is null)")
    public List<Position> findAllOfDepartment(String departmentId);

    @Query("from Position p where p.id not in (select dp.positionId from DepartToPosition dp where dp.departmentId = ?1) and p.deleteTime is null and (p.status=true or p.status is null)")
    public List<Position> findNoUse(String departmentId);
}
